home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / BUILDWP.C < prev    next >
C/C++ Source or Header  |  1996-08-29  |  3KB  |  126 lines

  1. #ifdef MSDOS
  2. #include <stdio.h>
  3. #include <dir.h>
  4. #include <dos.h>
  5. #include <time.h>
  6. #include <fcntl.h>
  7. #include <sys/stat.h>
  8.  
  9. #ifndef _lint
  10. static char rcsid[] OPTIONAL = "$Id: buildwp.c,v 1.6 1996/08/29 12:11:16 root Exp root $";
  11. #endif
  12.  
  13. char *WhitePages = "spool/wpagebbs";
  14. #define NULLFILE (FILE *) 0
  15. #define NULLCHAR (char *) 0
  16. #define LINELEN 128
  17. #define    READ_TEXT    "rt"
  18. #define    APPEND_TEXT    "at+"
  19.  
  20. void
  21. wpageUpdate(fp, string, entry, oldtime)
  22. FILE *fp;
  23. char *string, *entry, *oldtime;
  24. {
  25. time_t now;
  26.  
  27.     time(&now);
  28.     fprintf(fp,"%-32s %-14ld\n",entry,now); // update time stamp
  29. }
  30.  
  31.  
  32. /* Returns a copy (strdup'ed) of existing entry if string is in whitepages file */
  33. char *
  34. wpageCheck(string)
  35. char *string;
  36. {
  37. char buf[LINELEN], *cp, *retval = NULLCHAR;
  38. FILE *fp;
  39.  
  40.     if (string && ((fp = fopen(WhitePages,"r+t")) != NULLFILE))    {
  41.         while(fgets(buf, LINELEN, fp) != NULLCHAR)    {
  42.             /* Get rid of following spaces or tabs, to separate the
  43.              * h_addr and it's time stamp entry
  44.              */
  45.             if( ((cp=strchr(buf,' ')) != NULLCHAR) || \
  46.                 ((cp=strchr(buf,'\t')) != NULLCHAR) )
  47.                     *cp = '\0';
  48.             if(!strnicmp(string,buf, strlen(string)))    {
  49.                 retval = strdup (buf);
  50.                 fseek (fp, (long) -49, SEEK_CUR);
  51.                 wpageUpdate (fp, string, buf, &buf[33]);
  52.                 break;
  53.             }
  54.         }
  55.         fclose(fp);
  56.     }
  57.     return retval;
  58. }
  59.      
  60.  
  61. void
  62. wpageAdd (entry)
  63. char *entry;
  64. {
  65. time_t now;
  66. FILE *fp;
  67. char *last;
  68.  
  69.     if (entry == NULLCHAR)
  70.         return;
  71.     last = wpageCheck (entry);
  72.     free (last);
  73.     if (!last)    {
  74.         time(&now);
  75.         if((fp = fopen(WhitePages,APPEND_TEXT)) != NULLFILE) {
  76.             fprintf(fp,"%s %-14ld\n",entry,now); /* Save h_addr in whitepages file */
  77.             fclose(fp);
  78.         }
  79.     }
  80.  
  81. }
  82.  
  83.  
  84. main ()
  85. {
  86. FILE *tmpfile;
  87. struct ffblk ff;
  88. char buf[LINELEN], *cp, *cp2;
  89. char fname[32];
  90.  
  91.     strcpy(buf,"spool/mail/*.txt");
  92.     if (findfirst(buf, &ff, 0) == 0) {
  93.         do    {
  94.             sprintf (fname, "spool/mail/%s", ff.ff_name);
  95.             if ((tmpfile = fopen (fname,READ_TEXT)) != NULLFILE)    {
  96.                 while(fgets(buf,LINELEN,tmpfile) != NULLCHAR)    {
  97.                     if(!strnicmp(buf,"R:",2)) { /*found one*/
  98.                         /* Find the '@[:]CALL.STATE.COUNTRY'or
  99.                          * or the '?[:]CALL.STATE.COUNTRY' string
  100.                          * The : is optional.
  101.                          */
  102.                         if( ((cp=strchr(buf,'@')) != NULLCHAR) ||
  103.                             ((cp=strchr(buf,'?')) != NULLCHAR) ) {
  104.                                 if((cp2=strchr(cp,' ')) != NULLCHAR)
  105.                                     *cp2 = '\0';
  106.                                 if((cp2=strchr(cp,'\n')) != NULLCHAR)
  107.                                     *cp2 = '\0';
  108.                                 if((cp2=strchr(cp,'\t')) != NULLCHAR)
  109.                                     *cp2 = '\0';
  110.                                 /* Some bbs's send @bbs instead of @:bbs*/
  111.                                 if (*++cp == ':')
  112.                                     cp++;
  113.                                     wpageAdd (cp);
  114.                                     printf("%s: Adding '%s'\n", ff.ff_name, cp);
  115.                             }
  116.                     }
  117.                 }
  118.                 fclose (tmpfile);
  119.             }
  120.  
  121.         } while (findnext(&ff) == 0);
  122.     }
  123. }
  124. #endif /* MSDOS */
  125.  
  126.